{include file="public/head"}
<style>
    .caozuo .layui-btn {
        margin-left: auto;
    }

    .x-body {
        min-width: 1400px;
    }

    body {
        overflow-x: scroll;
    }
</style>
<body>
<div class="x-body">
    <div class="lotus-nav">
        <button class="layui-btn layui-btn-sm"
                onclick="x_admin_show('添加产品','productAdd.html?lang={$Think.get.lanid}&company_id={$Think.get.company_id}')">
            <i class="layui-icon layui-icon-add-circle"></i>新建
        </button>

        <div class="layui-input-inline">
            <input id="proname" name="proname" class="layui-input" placeholder="产品名称" value="{$Think.get.proname}">
        </div>

        <div class="layui-input-inline">
            <input id="code" name="code" class="layui-input" placeholder="SKU码" value="{$Think.get.code}">
        </div>

        <div class="layui-input-inline layui-form">
            <select name="platform" id="platform" lay-verify="platform">
                <option value="">商品平台</option>
                {volist name="platform" id="vo"}
                <option value="{$vo.english}" {if $Think.get.platformStr eq $vo['english']} selected {/if}>{$vo.name}</option>
                {/volist}
            </select>
        </div>

        <div class="layui-input-inline layui-form">
            <select name="lang" id="lang" lay-verify="lang" lay-search>
                <option value="">默认语言</option>
                {volist name="lang" id="vo"}
                <option value="{$vo.lanid}" {if $Think.get.lanid eq $vo['lanid']} selected {/if}>{$vo.lang}</option>
                {/volist}
            </select>
        </div>
        <input type="hidden" id="company_id" name="company_id" value="{$Think.get.company_id}">
        <div class="layui-input-inline layui-form" style="width: 150px">
            <select name="list_rows" id="list_rows">
                <option value="">每页产品数</option>
                {volist name="list_rows" id="vo"}
                {if $vo eq $Think.get.list_rows}
                <option value="{$vo}" selected>{$vo}</option>
                {else / }
                <option value="{$vo}">{$vo}</option>
                {/if}
                {/volist}
            </select>
        </div>
        <button class="layui-btn layui-btn-sm" onclick="search()">
            <i class="layui-icon layui-icon-search"></i>搜索
        </button>
        {if empty($Think.get.company_id)}
        <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delAll('{$Think.get.lanid}')"><i
                class="layui-icon"></i>批量删除
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="massAudit('{$Think.get.lanid}')">批量审核</button>
        {/if}
        <span class="x-right">共有数据:<i class="i_count">{$product->total()}</i>条
            <button onclick="javascript:location.reload()" class="layui-btn-default ">
                <i class="layui-icon layui-icon-refresh"></i>
            </button>
        </span>
    </div>


    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 55px;text-align:center">
                <div class="header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th style="width:100px;text-align:center">产品图</th>
            <th>产品标题</th>
            <th style="width: 80px;text-align:center">售价</th>
            <th style="min-width: 80px;text-align:center">SKU码</th>
            <th style="width: 60px;text-align:center">分类</th>
            <th style="width: 40px;text-align:center">来源</th>
            <th style="width: 60px;text-align:center">业务员</th>
            <th style="width: 60px;text-align:center">智赢状态</th>
            <th style="width: 75px;text-align:center">加入时间</th>
            {if empty($Think.get.company_id)}
            <th style="width: 160px;text-align:center">操作</th>
            {else/}
            <th style="width: 40px;text-align:center">操作</th>
            {/if}
        </thead>
        <tbody>

        {volist name="product" id="vo"}
        {if $vo.repeat eq 1}
        <tr class="layui-bg-orange">
        {else/}
        <tr>
        {/if}
            <td style="text-align:center">
                <div class="layui-form-checkbox" lay-skin="primary" data-id='{$vo.guid}'><i
                        class="layui-icon">&#xe605;</i></div>
                {$i}
            </td>
            <td style="text-align:center">
                {if isset($imgs[$vo['guid']]['imgpath'])}
                <img src="{$imgs[$vo['guid']]['imgpath']}" onclick="previewImg(this)">
                {else/}
                <img src="__images__/noimg.png">
                {/if}
            </td>
            <td>
                {if !empty($vo['fromurl'])}
                <a href="{$vo.fromurl}" style="color: #01AAED;" target="_blank">{$vo.proname}</a>
                {else/}
                {$vo.proname}
                {/if}
            </td>
            <td style="text-align:center">{$vo.coin}{$vo.saleprice}</td>
            <td style="text-align:center">{$vo.skucode}</td>
            <td style="text-align:center">{$vo.bname}</td>
            <td style="text-align:center">
                {if $vo['source'] == 1}未知
                {elseif $vo['source'] == 2}原创
                {else/}采集
                {/if}
            </td>
            <td style="text-align:center">{$vo.user_name}</td>
            <td style="text-align:center">
                {if $vo['iszy'] == 1}未上传
                {else/}已上传
                {/if}
            </td>
            <td style="text-align:center">{$vo.ndate}</td>
            <td class="caozuo">
                {if ssession('username') eq $vo.user_name}
                <button class="layui-btn layui-btn-xs"
                        onclick="x_admin_show('编辑','productEdit.html?id={$vo.id}&lang={$Think.get.lanid}&company_id={$Think.get.company_id}')">
                    编辑
                </button>
                {else/}
                <button class="layui-btn layui-btn-xs"
                        onclick="x_admin_show('详情','productInfo.html?id={$vo.id}&lang={$Think.get.lanid}&company_id={$Think.get.company_id}')">
                    详情
                </button>
                {/if}
                {if empty($Think.get.company_id)}
                <button onclick="del(this,'{$vo.guid}','{$Think.get.lanid}')"
                        class="layui-btn layui-btn-xs layui-btn-danger">
                    删除
                </button>

                {if $vo['audit'] == 1}
                <button onclick="audit(this,'{$vo.guid}','{$Think.get.lanid}',2,'{$vo.id}')"
                        class="layui-btn layui-btn-xs layui-btn-normal">
                    审核
                </button>

                <button onclick="audit(this,'{$vo.guid}','{$Think.get.lanid}',3,'{$vo.id}')"
                        class="layui-btn layui-btn-xs layui-bg-cyan">
                    侵权
                </button>
                {elseif ($vo['audit'] == 2) && ($Think.get.lanid == '')}
                {if ssession('username') eq $vo.user_name}
                <button class="layui-btn layui-btn-xs layui-btn-normal"
                        onclick="x_admin_show('一键翻译','fanyi.html?id={$vo.id}&lang={$Think.get.lanid}&company_id={$Think.get.company_id}')">
                    一键翻译
                </button>
                {/if}
                {/if}
                {/if}
            </td>
        </tr>
        {/volist}

        </tbody>
    </table>
    <div class="page">
        <div>
            {$product->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    function search() {
        var html = '';
        html += "&list_rows=" + $("#list_rows").val();
        html += "&proname=" + $("#proname").val();
        html += "&code=" + $("#code").val();
        html += "&lanid=" + $("#lang").val();
        html += "&company_id=" + $("#company_id").val();
        html += "&platformStr=" + $("#platform").val();
        location.href = "productListAudit.html?" + html;
    }

    //删除所有
    function delAll(lang) {
        var data = tableCheck.getData();
        if (data.length == 0) {
            layer.msg("请选择需要删除的产品");
            return false;
        }
        layer.confirm('确认要全部删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/product/delete')}", {guid: data, lang: lang}, function (data, textStatus, xhr) {
                console.log(data);
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    function del(obj, guid, lang) {
        var count = $(".i_count")[0].innerText;
        layer.confirm('确认要删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/product/delete')}", {guid: guid, lang: lang}, function (data, textStatus, xhr) {
                /*optional stuff to do after success */
                // console.log(data);
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(obj).parents('tr').remove();
                        $(".i_count").html(count - 1);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    function audit(obj, guid, lang, type, id) {
        var info = type == 2 ? "审核通过" : "侵权";
        layer.confirm('确认该产品' + info + '？', function (index) {
            $.post("{:url('admin/product/audit')}", {
                guid: guid,
                lang: lang,
                audit: type,
                id: id
            }, function (data, textStatus, xhr) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000});
                    location.reload();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
    //批量审核
    function massAudit(lang) {
        var data = tableCheck.getData();
        if (data.length == 0) {
            layer.msg("请选择需要审核的产品");
            return false;
        }
        layer.confirm('确认要全部审核吗？', function (index) {
            layer.load(1);
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/product/audit')}", {guid: data, lang: lang}, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
</script>
